"use strict";
const electron = require("electron");
function displayUpdateMessage(message) {
  alert(message);
}
electron.ipcRenderer.on("update-message", (_, message) => {
  displayUpdateMessage(message);
});
electron.ipcRenderer.on("update-ready", (_event, message) => {
  const notification = new Notification("应用更新", {
    body: message,
    icon: "/path/to/icon.png"
    // 替换为你的应用图标路径
  });
  setTimeout(() => notification.close(), 5e3);
});
if (Notification.permission !== "granted") {
  Notification.requestPermission().then((permission) => {
    if (permission === "granted") {
      console.log("用户已授权通知");
    } else {
      console.warn("用户未授权通知");
    }
  });
}
electron.contextBridge.exposeInMainWorld("ipcRenderer", {
  on(...args) {
    const [channel, listener] = args;
    return electron.ipcRenderer.on(channel, (event, ...args2) => listener(event, ...args2));
  },
  off(...args) {
    const [channel, ...omit] = args;
    return electron.ipcRenderer.off(channel, ...omit);
  },
  send(...args) {
    const [channel, ...omit] = args;
    return electron.ipcRenderer.send(channel, ...omit);
  },
  invoke(...args) {
    const [channel, ...omit] = args;
    return electron.ipcRenderer.invoke(channel, ...omit);
  }
});
electron.contextBridge.exposeInMainWorld("fileAPI", {
  navigateWithPlaywright: (url, orderNumbersArray, isHeadless) => electron.ipcRenderer.send("navigate-with-playwright", url, orderNumbersArray, isHeadless)
});
electron.contextBridge.exposeInMainWorld("electron", {
  send: (channel, data) => {
    electron.ipcRenderer.send(channel, data);
  },
  // 从渲染进程发送消息到主进程的示例函数
  receive: (channel, func) => {
    electron.ipcRenderer.on(channel, (_event, ...args) => func(...args));
  }
  // 从主进程接收消息到渲染进程的示例函数注册器
});
electron.contextBridge.exposeInMainWorld("notification", {
  create(title, options) {
    return new Notification(title, options);
  },
  requestPermission() {
    return Notification.requestPermission();
  }
});
electron.contextBridge.exposeInMainWorld("electronAPI", {
  loadPlugin: (pluginId) => electron.ipcRenderer.invoke("load-plugin", pluginId),
  writeData: () => electron.ipcRenderer.invoke("write-data"),
  executeChildProcess: (command) => electron.ipcRenderer.invoke("execute-child-process", command),
  runPlugin: (pluginId) => electron.ipcRenderer.invoke("run-plugin", pluginId),
  downloadPlugin: (pluginId, downloadUrl) => electron.ipcRenderer.invoke("download-plugin", pluginId, downloadUrl),
  getSheetIds: () => electron.ipcRenderer.invoke("getSheetIds"),
  saveSheetIds: (ids) => electron.ipcRenderer.invoke("saveSheetIds", ids),
  readCellData: (spreadsheetId, range) => electron.ipcRenderer.invoke("read-cell-data", spreadsheetId, range),
  readColumnData: (spreadsheetId, range) => electron.ipcRenderer.invoke("google-api:readColumnData", spreadsheetId, range),
  readRowData: (spreadsheetId, range) => electron.ipcRenderer.invoke("google-api:readRowData", spreadsheetId, range),
  updateRowData: (spreadsheetId, plmCode, rowData, range) => electron.ipcRenderer.invoke("google-api:updateRowData", spreadsheetId, plmCode, rowData, range),
  getSheetNames: (spreadsheetId) => electron.ipcRenderer.invoke("getSheetNames", spreadsheetId),
  updatePartialColumns: (spreadsheetId, sheetName, plmCode, updates, range) => electron.ipcRenderer.invoke("update-partial-columns", spreadsheetId, sheetName, plmCode, updates, range),
  saveSettings: (settings) => electron.ipcRenderer.invoke("save-settings", settings),
  getUserSettings: () => electron.ipcRenderer.invoke("get-user-settings"),
  sendMonitoringData: (data) => electron.ipcRenderer.invoke("send-monitoring-data", data)
});
